Skip to content

refactor: Improve data repository lifecycle safety - #194

Merged
ProdigyV21 merged 2 commits into
ProdigyV21:mainfrom
Himanth-reddy:chore/auto-refactor-2026-05-15-13087954862751201397
May 15, 2026
Merged

refactor: Improve data repository lifecycle safety#194
ProdigyV21 merged 2 commits into
ProdigyV21:mainfrom
Himanth-reddy:chore/auto-refactor-2026-05-15-13087954862751201397

Conversation

@Himanth-reddy

@Himanth-reddy Himanth-reddy commented May 15, 2026

Copy link
Copy Markdown
Collaborator

Original PR #11 Context

Source PR: Himanth-reddy#11

CodeRabbit walkthrough from PR #11:

Three independent repository class refactorings improve stream resolution logic clarity, add atomic lifecycle state management to prevent concurrent starts, and reorganize telemetry DataStore keys into a companion object.

Original Changes

Layer / File(s) Summary
Stream resolution optimization
app/src/main/kotlin/com/arflix/tv/data/repository/AddonRuntimeAggregator.kt
resolveMovieStreams and resolveEpisodeStreams now use early returns on empty input and direct STREMIO runtime resolution with .orEmpty(), removing intermediate mutable lists and conditional blocks.
Lifecycle thread-safety
app/src/main/kotlin/com/arflix/tv/data/repository/CloudSyncCoordinator.kt
started state changed from volatile boolean to AtomicBoolean, with start() using atomic compareAndSet(false, true) for idempotent behavior and stop() resetting via set(false).
Telemetry key organization
app/src/main/kotlin/com/arflix/tv/data/repository/PlaybackTelemetryRepository.kt
DataStore preference keys (startupSamplesKey, startupAvgMsKey, and telemetry counters) moved from instance-level properties into a private companion object.

Review Feedback Addressed

CodeRabbit flagged a remaining lifecycle race in CloudSyncCoordinator.kt: AtomicBoolean.compareAndSet serialized concurrent start() calls, but did not protect collectorJob and flushJob from a concurrent stop() call. That could allow start() to assign a live job after stop() had nulled the job fields, leaving coroutine work running while started == false.

CodeRabbit also suggested replacing the fully-qualified java.util.concurrent.atomic.AtomicBoolean usage with an import.

Additional Commit Added

Commit: c7d0944 fix: synchronize cloud sync coordinator lifecycle

This commit:

  • Adds a shared lifecycleLock in CloudSyncCoordinator.
  • Synchronizes start() and stop() so started, collectorJob, and flushJob are updated together.
  • Synchronizes scheduleFlush() and skips scheduling if the coordinator has already stopped.
  • Cancels/replaces flushJob under the same lifecycle lock.
  • Imports AtomicBoolean directly and uses AtomicBoolean(false).

Validation

  • ./gradlew assembleSideloadDebug --no-daemon

Himanth-reddy and others added 2 commits May 15, 2026 07:05
Refactored DataStore keys into a companion object in PlaybackTelemetryRepository.
Modernized list generation in AddonRuntimeAggregator to avoid mutable list allocation.
Fixed concurrency flaw in CloudSyncCoordinator by replacing @volatile with AtomicBoolean.
@ProdigyV21
ProdigyV21 merged commit a74dd13 into ProdigyV21:main May 15, 2026
1 check passed
@Himanth-reddy
Himanth-reddy deleted the chore/auto-refactor-2026-05-15-13087954862751201397 branch July 23, 2026 10:23
@Himanth-reddy Himanth-reddy added gssoc-approved level:intermediate Intermediate level task quality:clean Clean code implementation type:refactor Code refactoring and cleanups gssoc:approved GSSoC approved contribution and removed gssoc:approved labels Jul 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved GSSoC approved contribution level:intermediate Intermediate level task quality:clean Clean code implementation type:refactor Code refactoring and cleanups

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants